package cn.xo68.boot.auth.server.mapper;


import cn.xo68.boot.auth.server.domain.OauthUser;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Oauth2User mybatis mapper
 * @author wuyy(16349023@qq.com)
 * @date 2018年08月04日 16:22:17
 *
 */
public interface OauthUserMapper {


    @Select("SELECT * FROM oauth_user WHERE user_id = #{userId}")
    @Results(value = {
            @Result(id = true, column = "user_id", property = "userId"),
            @Result(column = "account", property = "account"),
            @Result(column = "user_pass", property = "userPass"),
            @Result(column = "user_name", property = "userName"),
            @Result(column = "sex", property = "sex"),
            @Result(column = "user_type", property = "userType"),
            @Result(column = "birthday", property = "birthday"),
            @Result(column = "phone", property = "phone"),
            @Result(column = "email", property = "email"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "last_login_time", property = "lastLoginTime"),
            @Result(column = "login_count", property = "loginCount"),
            @Result(column = "user_lock", property = "userLock")
    })
    OauthUser getByUserId(@Param("userId") String userId);

	@Select("SELECT * FROM oauth_user WHERE account = #{account}")
    @Results(value = {
    @Result(id = true, column = "user_id", property = "userId"),
        @Result(column = "account", property = "account"),
        @Result(column = "user_pass", property = "userPass"),
        @Result(column = "user_name", property = "userName"),
        @Result(column = "sex", property = "sex"),
        @Result(column = "user_type", property = "userType"),
        @Result(column = "birthday", property = "birthday"),
        @Result(column = "phone", property = "phone"),
        @Result(column = "email", property = "email"),
        @Result(column = "create_time", property = "createTime"),
        @Result(column = "last_login_time", property = "lastLoginTime"),
        @Result(column = "login_count", property = "loginCount"),
        @Result(column = "user_lock", property = "userLock")
    })
    OauthUser getByAccount(@Param("account") String account);
	
	@Select("SELECT * FROM oauth_user WHERE user_id = #{userId}")
    @Results(value = { 
    @Result(id = true, column = "user_id", property = "userId"),
        @Result(column = "account", property = "account"),
        @Result(column = "user_pass", property = "userPass"),
        @Result(column = "user_name", property = "userName"),
        @Result(column = "sex", property = "sex"),
        @Result(column = "user_type", property = "userType"),
        @Result(column = "birthday", property = "birthday"),
        @Result(column = "phone", property = "phone"),
        @Result(column = "email", property = "email"),
        @Result(column = "create_time", property = "createTime"),
        @Result(column = "last_login_time", property = "lastLoginTime"),
        @Result(column = "login_count", property = "loginCount"),
        @Result(column = "user_lock", property = "userLock")
    })
    OauthUser find(@Param("userId") String userId);
	
	@Select("SELECT * FROM oauth_user")
    @Results(value = { 
    @Result(id = true, column = "user_id", property = "userId"),
        @Result(column = "account", property = "account"),
        @Result(column = "user_pass", property = "userPass"),
        @Result(column = "user_name", property = "userName"),
        @Result(column = "sex", property = "sex"),
        @Result(column = "user_type", property = "userType"),
        @Result(column = "birthday", property = "birthday"),
        @Result(column = "phone", property = "phone"),
        @Result(column = "email", property = "email"),
        @Result(column = "create_time", property = "createTime"),
        @Result(column = "last_login_time", property = "lastLoginTime"),
        @Result(column = "login_count", property = "loginCount"),
        @Result(column = "user_lock", property = "userLock")
    })
    List<OauthUser> list();
	
	@Insert("insert into oauth_user (user_id ,account ,user_pass ,user_name ,sex ,user_type ,birthday ,phone ,email ,create_time ,last_login_time ,login_count ,user_lock ) values (#{userId} , #{account} , #{userPass} , #{userName} , #{sex} , #{userType} , #{birthday} , #{phone} , #{email} , #{createTime} , #{lastLoginTime} , #{loginCount} , #{userLock}  )")
    @Options(useGeneratedKeys = true, keyProperty = "userId")
    void insert(OauthUser oauth2User);
	
	@Update("update oauth_user set  account=#{account}, user_pass=#{userPass}, user_name=#{userName}, sex=#{sex}, user_type=#{userType}, birthday=#{birthday}, phone=#{phone}, email=#{email}, create_time=#{createTime}, last_login_time=#{lastLoginTime}, login_count=#{loginCount}, user_lock=#{userLock} where user_id = #{userId}")
    void update(OauthUser oauth2User);

	@Delete("delete FROM oauth_user WHERE user_id = #{userId}")
	void delete(@Param("userId") String userId);
}